package com.lgh.hotel.controller;

import com.lgh.hotel.common.aop.LogAnnotation;
import com.lgh.hotel.service.TableServer;
import com.lgh.hotel.vo.Result;
import com.lgh.hotel.vo.params.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "房间模块")
@RestController
@RequestMapping("table")
public class TableController {

    @Autowired
    TableServer tableServer;

    @ApiOperation(value = "获取所有未住人的房间")
    @GetMapping
    public Result table(){
        return tableServer.findTableNoState();
    }

    @ApiOperation(value = "分页获取房间")
    @PostMapping("/findTable/page")
    public Result findAllTable(@RequestBody PageParams params){
        return tableServer.findTbalePagesList(params);
    }

    @ApiOperation(value = "删除房间")
    @GetMapping("/deteleTable/{id}")
    public Result deteleTable(@PathVariable("id") Long id){
        return tableServer.deteleTable(id);
    }

    @LogAnnotation
    @ApiOperation("获取所有房间")
    @GetMapping("/findAllTable")
    public Result findalltable(){
//        System.out.println(principal.getName());
        return tableServer.findTableAll();
    }

    @ApiOperation("更新房间信息")
    @PutMapping("/update/Table")
    public Result updateTable(@RequestHeader("Authorization")String token,@RequestBody TableParamsa tableParams){
        System.out.println(token);
        return tableServer.updateTable(tableParams,token,true);
    }


    @LogAnnotation
    @ApiOperation("入住房间")
    @PostMapping("/addTable")
    public Result addTable(@RequestBody TableParam tableParam){
        return tableServer.addTable(tableParam);
    }


    @LogAnnotation
    @ApiOperation("添加房间")
    @PostMapping("/addTables")
    public Result addTables(@RequestHeader("Authorization")String token,@RequestBody TableParamss tableParams){

        return tableServer.addTables(tableParams,token);
    }


    @LogAnnotation
    @ApiOperation("退房")
    @GetMapping("/tuifang/{id}")
    public Result tuifang(@PathVariable("id")Long id){
        return tableServer.tuifang(id);
    }


    @LogAnnotation
    @ApiOperation("入住房间")
    @PostMapping("/beysucc")
    public Result beysucc(@RequestBody TableParam tableParam){
        return tableServer.beysucc(tableParam);
    }


    @LogAnnotation
    @ApiOperation("疫情入住（隔离十四天）")
    @PostMapping("/yiqingruzhu")
    public Result yiqingruzhu(@RequestBody TableParam tableParam){
        return tableServer.yiqingruzhu(tableParam);
    }

}
